package io.renren.modules.pullin.DataConversion;
import io.renren.modules.jxgk.utils.UUidCreater;
import io.renren.modules.pullin.entity.DateInfomation;
import io.renren.modules.pullin.entity.ClassCourse;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class TeachControlView {
    public List InformationSet(String xkkh,String kcmc,String bjmc,String jsxm,String jszgh,String xq,String xn,String position,String time,String xsxy){
        String begin1="周",begin2="第",begin3="第",begin4="-";
        String end1="第",end2=",",end3="-",end4="周";
        String[] pos=new String[100];
        String[] tim=new String[100];
        if(position==null){

        } else {
            pos=position.split(";");
        }
        tim=time.split(";");
        List<ClassCourse> Clist=new ArrayList<>();
        for(int i=0;i<tim.length;i++){
            UUidCreater uuid=new UUidCreater();
            DateInfomation dateInfomation=new DateInfomation();
            //周四第1,2节{第1-19周|单周};周四第1,2节{第2-20周|双周}
            if(tim[i].indexOf("单周")!=-1){
                String day = tim[i].substring(tim[i].indexOf("周")+1,tim[i].indexOf("周")+2);
                String index = tim[i].substring(tim[i].indexOf("第")+1,tim[i].indexOf("第")+2);
                String week = tim[i].substring(tim[i].indexOf("{第")+2,tim[i].indexOf("周|单周"));
                String[] week2=week.split("-");
                if(day.equals("一"))
                    dateInfomation.setDay("1");
                if(day.equals("二"))
                    dateInfomation.setDay("2");
                if(day.equals("三"))
                    dateInfomation.setDay("3");
                if(day.equals("四"))
                    dateInfomation.setDay("4");
                if(day.equals("五"))
                    dateInfomation.setDay("5");
                if(day.equals("六"))
                    dateInfomation.setDay("6");
                dateInfomation.setIndex(index);
                dateInfomation.setStartweek(Integer.valueOf(week2[0]).intValue());
                dateInfomation.setEndweek(Integer.valueOf(week2[1]).intValue());
                if(position==null||position.length()<3){
                    dateInfomation.setPosition("");
                } else {
                    System.out.println(tim.length);
                    dateInfomation.setPosition(pos[i]);
                }

                for(int j=dateInfomation.getStartweek();j<=dateInfomation.getEndweek();j+=2){
                    ClassCourse classCourse=new ClassCourse();
                    Clist.add(classCourse);
                    classCourse.setCourse_which_day(dateInfomation.getDay());
                    classCourse.setCourse_which_index(dateInfomation.getIndex());
                    classCourse.setCourse_which_week(j+"");
                    classCourse.setCourse_classroom_position(dateInfomation.getPosition());
                    classCourse.setClass_id(uuid.getUUID());
                    classCourse.setClass_course_id(uuid.getUUID());
                    classCourse.setCourse_academic_term(xq);
                    classCourse.setCourse_academic_year(xn);
                    classCourse.setClass_name(bjmc);
                    classCourse.setCourse_school_id(xkkh);
                    classCourse.setCourse_name(kcmc);
                    classCourse.setCourse_teacher_id(jszgh);
                    classCourse.setCourse_teacher_name(jsxm);
                    classCourse.setStudent_department_name(xsxy);
                }
            }else if(tim[i].indexOf("双周")!=-1){
                String day = tim[i].substring(tim[i].indexOf("周")+1,tim[i].indexOf("周")+2);
                String index = tim[i].substring(tim[i].indexOf("第")+1,tim[i].indexOf("第")+2);
                String week = tim[i].substring(tim[i].indexOf("{第")+2,tim[i].indexOf("周|双周"));
                String[] week2=week.split("-");
                if(day.equals("一"))
                    dateInfomation.setDay("1");
                if(day.equals("二"))
                    dateInfomation.setDay("2");
                if(day.equals("三"))
                    dateInfomation.setDay("3");
                if(day.equals("四"))
                    dateInfomation.setDay("4");
                if(day.equals("五"))
                    dateInfomation.setDay("5");
                if(day.equals("六"))
                    dateInfomation.setDay("6");
                dateInfomation.setIndex(index);
                dateInfomation.setStartweek(Integer.valueOf(week2[0]).intValue());
                dateInfomation.setEndweek(Integer.valueOf(week2[1]).intValue());
                if(position==null||position.length()<3){
                    dateInfomation.setPosition("");
                } else {
                    System.out.println(tim.length);
                    dateInfomation.setPosition(pos[i]);
                }
                for(int j=dateInfomation.getStartweek();j<=dateInfomation.getEndweek();j+=2){
                    ClassCourse classCourse=new ClassCourse();
                    Clist.add(classCourse);
                    classCourse.setCourse_which_day(dateInfomation.getDay());
                    classCourse.setCourse_which_index(dateInfomation.getIndex());
                    classCourse.setCourse_which_week(j+"");
                    classCourse.setCourse_classroom_position(dateInfomation.getPosition());
                    classCourse.setClass_id(uuid.getUUID());
                    classCourse.setClass_course_id(uuid.getUUID());
                    classCourse.setCourse_academic_term(xq);
                    classCourse.setCourse_academic_year(xn);
                    classCourse.setClass_name(bjmc);
                    classCourse.setCourse_school_id(xkkh);
                    classCourse.setCourse_name(kcmc);
                    classCourse.setCourse_teacher_id(jszgh);
                    classCourse.setCourse_teacher_name(jsxm);
                    classCourse.setStudent_department_name(xsxy);
                }
            } else{
                String day = tim[i].substring(tim[i].indexOf("周")+1,tim[i].indexOf("周")+2);
                String index = tim[i].substring(tim[i].indexOf("第")+1,tim[i].indexOf("第")+2);
                String jie1 = tim[i].substring(tim[i].indexOf("{第")+2,tim[i].indexOf("周}"));
                String[] week=jie1.split("-");
                if(day.equals("一"))
                    dateInfomation.setDay("1");
                if(day.equals("二"))
                    dateInfomation.setDay("2");
                if(day.equals("三"))
                    dateInfomation.setDay("3");
                if(day.equals("四"))
                    dateInfomation.setDay("4");
                if(day.equals("五"))
                    dateInfomation.setDay("5");
                if(day.equals("六"))
                    dateInfomation.setDay("6");
                dateInfomation.setIndex(index);
                dateInfomation.setStartweek(Integer.valueOf(week[0]).intValue());
                dateInfomation.setEndweek(Integer.valueOf(week[1]).intValue());
                if(position==null||position.length()<3){
                    dateInfomation.setPosition("");
                } else {
                    System.out.println(tim.length);
                    dateInfomation.setPosition(pos[i]);
                }

                for(int j=dateInfomation.getStartweek();j<=dateInfomation.getEndweek();j++){
                    ClassCourse classCourse=new ClassCourse();
                    Clist.add(classCourse);
                    classCourse.setCourse_which_day(dateInfomation.getDay());
                    classCourse.setCourse_which_index(dateInfomation.getIndex());
                    classCourse.setCourse_which_week(j+"");
                    classCourse.setCourse_classroom_position(dateInfomation.getPosition());
                    classCourse.setClass_id(uuid.getUUID());
                    classCourse.setClass_course_id(uuid.getUUID());
                    classCourse.setCourse_academic_term(xq);
                    classCourse.setCourse_academic_year(xn);
                    classCourse.setClass_name(bjmc);
                    classCourse.setCourse_school_id(xkkh);
                    classCourse.setCourse_name(kcmc);
                    classCourse.setCourse_teacher_id(jszgh);
                    classCourse.setCourse_teacher_name(jsxm);
                    classCourse.setStudent_department_name(xsxy);
                }
            }
        }
        return Clist;
    }
    public void ShowInfo(List<ClassCourse> l){
        for(ClassCourse c:l){
            System.out.print("教学周:"+c.getCourse_which_week());
            System.out.print("周:"+c.getCourse_which_day());
            System.out.print("第"+c.getCourse_which_index()+"->>");
            if(c.getCourse_which_index().equals("3708"))
            {
                System.out.print("第"+c.getCourse_which_index()+"->>");
            }
            System.out.print(c.getCourse_classroom_position());
            System.out.println("");
        }
    }
    public static void appendMethodB(String fileName, String content) {
        try {
            //打开一个写文件器，构造函数中的第二个参数true表示以追加形式写文件
            FileWriter writer = new FileWriter(fileName, true);
            writer.write(content);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String []args){
        TeachControlView t=new TeachControlView();
        String info2="1号教学楼C601;1号教学楼C601";
        String info="周二第1,2节{第1-20周};周三第3,4节{第1-20周}";
        String info3="周二第1,2节{第1-20周}";
        String info4="1号教学楼C601";
        //t.ShowInfo(t.InformationSet(info4,info3));
    }
}
